package com.xnyzc.lhy.order.mapper.vehicle;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xnyzc.lhy.order.entity.cms.vehicle.VehicleManageInfo;
import com.xnyzc.lhy.order.entity.vehicle.OaSysVehicle;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 车辆信息表 Mapper 接口
 * </p>
 *
 * @author bin
 * @since 2019-07-22
 */
public interface OaSysVehicleMapper extends BaseMapper<OaSysVehicle> {


    /**
     * 分页获取车辆信息
     *
     * @param iPage
     * @return
     */
    @Select("SELECT " +
            "oa_sys_vehicle.*," +
            "oa_sys_dict.label,  " +
            "oa_sys_dict.value, " +
            "oa_vehicle_series.vehicle_type," +
            "oa_sys_office.name  " +
            "FROM " +
            "oa_sys_vehicle," +
            "oa_sys_dict,  " +
            "oa_vehicle_series," +
            "oa_sys_office   " +
            "WHERE " +
            "oa_sys_vehicle.veh_color = oa_sys_dict.value  " +
            "AND oa_sys_dict.type = 'vegicle_color_type'  " +
            "AND oa_sys_vehicle.deleted=0 " +
            "AND oa_sys_dict.deleted=0  " +
            "AND oa_vehicle_series.deleted = 0   " +
            "AND oa_sys_vehicle.code = oa_vehicle_series.code   " +
            "AND oa_sys_vehicle.company_id = oa_sys_office.office_id    " +
            "ORDER BY create_time DESC ")
    List<VehicleManageInfo> getVehicleList(IPage iPage);


    /**
     * 分页模糊查询车辆信息
     *
     * @param iPage：分页器
     * @param veh_status：车辆状态（0：空闲、1：维修中、2：使用中）
     * @param veh_color：车辆颜色（参见字典表）
     * @param veh_type：车辆类型(0-经济型,1-舒适性,2-商务型，3-豪华型)
     * @param veh_no：车牌号
     * @return
     */
    @Select("SELECT " +
            "oa_sys_vehicle.*," +
            "oa_sys_dict.label,  " +
            "oa_sys_dict.value,   " +
            "oa_vehicle_series.vehicle_type," +
            "oa_sys_office.name         " +
            "FROM " +
            "oa_sys_vehicle," +
            "oa_sys_dict, " +
            "oa_vehicle_series," +
            "oa_sys_office     " +
            "WHERE " +
            "oa_sys_vehicle.veh_color = oa_sys_dict.value  " +
            "AND oa_sys_dict.type = 'vegicle_color_type'  " +
            "AND oa_sys_vehicle.deleted=0 " +
            "AND oa_sys_dict.deleted=0  " +
            "AND oa_vehicle_series.deleted = 0   " +
            "AND oa_sys_vehicle.code = oa_vehicle_series.code  " +
            "AND oa_sys_vehicle.company_id = oa_sys_office.office_id       " +
            "AND oa_sys_vehicle.veh_status LIKE #{veh_status}   " +
            "AND oa_sys_vehicle.company_id LIKE #{companyId}   " +
            "AND oa_vehicle_series.vehicle_type LIKE #{veh_type} " +
            "AND oa_sys_vehicle.veh_no LIKE #{veh_no} " +
            "ORDER BY create_time DESC ")
    List<VehicleManageInfo> getVehicleListLike(IPage iPage,
                                               @Param("veh_status") String veh_status,
                                               @Param("companyId") String companyId,
                                               @Param("veh_type") String veh_type,
                                               @Param("veh_no") String veh_no);


    /**
     * 获取车辆信息Excel 导出
     *
     * @return
     */
    @Select("SELECT " +
            "oa_sys_vehicle.*," +
            "oa_sys_dict.label,  " +
            "oa_sys_dict.value   " +
            "FROM " +
            "oa_sys_vehicle," +
            "oa_sys_dict " +
            "WHERE " +
            "oa_sys_vehicle.veh_color = oa_sys_dict.value  " +
            "AND oa_sys_dict.type = 'vegicle_color_type'  " +
            "AND oa_sys_vehicle.deleted=0 " +
            "AND oa_sys_dict.deleted=0   " +
            "ORDER BY create_time DESC ")
    List<VehicleManageInfo> exportGetVehicle();


    @Select("SELECT  " +
            "oa_sys_vehicle.*,oa_sys_office.name   " +
            "from oa_sys_vehicle,oa_sys_office  " +
            "where oa_sys_vehicle.vehicle_id = #{vehicleId}  " +
            "and oa_sys_vehicle.company_id = oa_sys_office.office_id")
    VehicleManageInfo getVehicleDetails( @Param("vehicleId")Long vehicleId);

}
